import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state:{
        username:window.localStorage.getItem('username') == null ? '' : JSON.parse(window.localStorage.getItem('username' || '[]')),
        adminMenus:[],
        radio:window.localStorage.getItem('radio') == null ? '' : JSON.parse(window.localStorage.getItem('radio' || '[]'))
    },
    mutations:{
        initAdminMenu (state,menus){
            state.adminMenus=menus
        },
        login(state,[data,radio1]){
           
            state.radio=radio1
            state.username=data
            window.localStorage.setItem('username', JSON.stringify(data))
            window.localStorage.setItem('radio', JSON.stringify(radio1))
        },
        logout(state){
            state.username = '',
            window.localStorage.removeItem('username'),       
            state.adminMenus=[],
            state.radio='',
            window.localStorage.removeItem('radio')  
        }
    },
    actions:{
        
    }
})